#========================================
# author: changlong.zang
#   mail: zclongpop@163.com
#   date: Tue, 11 Aug 2015, 14:15:06
#========================================
import os, inspect
#--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
def getParentClasses(obj):
    '''
    Get object's all of parent class...
    '''
    if type(obj) == type:
        return inspect.getmro(obj)
    else:
        return inspect.getmro(obj.__class__)



def getModulesPath(moudle):
    '''
    return dir for imported moudle..
    '''
    moduleFile = inspect.getfile(moudle)
    modulePath = os.path.dirname(moduleFile)
    return modulePath




def getScriptPath():
    '''
    return dir path for used script..
    '''
    scriptPath = getModulesPath(inspect.currentframe().f_back)
    return scriptPath




def getResourcePath():
    '''
    return resource path for this rig system...
    '''
    path = getScriptPath()
    while True:
        resource_path = os.path.join(path, 'resource')
        #- find resource path
        if os.path.isdir(resource_path):
            return resource_path
        #- can't find resource path, return root path
        if path == os.path.dirname(path):
            return path
        #- next.
        path = os.path.dirname(path)





def arrayRemoveDuplicates(Array):
    '''
    [1,1,2,2,3,3,4,5,5,6,6,6,6] -> [1,2,3,4,5,6]
    '''
    if not isinstance(Array, (list, tuple)):
        return Array
    return [x for i, x in enumerate(Array) if x not in Array[:i]]





def openMultiarray(Array):
    '''
    [1, [2, [3, 4], 5], 6] -> [1, 2, 3, 4, 5, 6]
    (1, (2, (3, 4), 5), 6) -> (1, 2, 3, 4, 5, 6)
    '''
    for Item in Array:
        if isinstance(Item, (tuple, list)):
            for i in openMultiarray(Item):
                yield i
        else:
            yield Item
